<template>
  <div class="contain">
    <div class="contain-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>问诊订单记录</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="contain-body">
      <div class="body-header">
        <el-form :inline="true" size="mini">
          <el-form-item label="患者姓名">
            <el-input placeholder="请输入患者姓名" v-model="page.realName"></el-input>
          </el-form-item>
          <el-form-item label="订单号">
            <el-input placeholder="请输入订单号" v-model="page.orderNum"></el-input>
          </el-form-item>
          <el-form-item label="下单时间">
            <el-date-picker
                v-model="page.orderTime"
                value-format="yyyy-MM-dd"
                type="date"
                placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="订单类型">
            <el-select placeholder="请选择订单类型" clearable v-model="page.status">
              <el-option label="问诊中订单" value="3"></el-option>
              <el-option label="已完结订单" value="4"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="接诊医生" v-if="userInfo.role===3">
            <el-select placeholder="请选择接诊医生" v-model="page.doctorId" clearable>
              <el-option :label="item.realName" :value="item.id" v-for="item in doctorList" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="findPage">查 询</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="reset">刷 新</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="body-table">
        <el-table
            :data="tableData"
            @cell-dblclick="copyText"
            style="width: 100%">
          <el-table-column
              type="index"
              label="序号"
              width="50px"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="orderNum"
              label="订单号"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="client.realName"
              label="患者姓名"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="sex"
              label="性别"
              align="center"
          >
            <template slot-scope="scope">
              {{ scope.row.sex === 1 ? '男' : '女' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="client.age"
              label="年龄"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="morbidityTime"
              label="发病时间"
              align="center"
          >
          </el-table-column>
          <el-table-column
              label="主要临床表现"
              align="center"
              show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{'发热第'+scope.row.feverDayNum +'天;最高'+scope.row.highTemperature+'度;'+scope.row.symptomDetail}}
            </template>
          </el-table-column>
          <el-table-column
              prop="client.parentMobile"
              label="家长电话"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="doctorUser.realName"
              label="接诊医生"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="consultationFee"
              label="问诊费用"
              align="center"
          >
          </el-table-column>
          <el-table-column
              prop="orderTime"
              label="下单时间"
              width="300"
              align="center"
          >
          </el-table-column>
          <el-table-column
              label="订单状态"
              align="center"
          >
            <template slot-scope="scope">
              <el-tag :type="scope.row.status === 2 ? 'info' : scope.row.status === 3? '' : 'success'" size="mini">
                {{ scope.row.status === 2 ? '待接诊' : scope.row.status === 3 ? '问诊中' : '已完成' }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
              label="操作"
              align="center"
          >
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="getInOrderDetails(scope.row.id)">查 看</el-button>
              <el-button type="text" size="mini" v-if="userInfo.role===2&&scope.row.status===2"
                         @click="startOrder(scope.row.id)">接 诊
              </el-button>
            </template>
          </el-table-column>

        </el-table>
      </div>
      <div class="body-page">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page.pageIndex"
            :page-sizes="[10, 15, 20, 25]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        </el-pagination>
      </div>
    </div>

    <!--    <el-dialog-->
    <!--        title="查看患者信息"-->
    <!--        :visible.sync="seeDialog"-->
    <!--        width="50%"-->
    <!--    >-->
    <!--      <el-tabs v-model="activeName">-->
    <!--        <el-tab-pane label="临床表现" name="1"></el-tab-pane>-->
    <!--        <el-tab-pane label="体温检测" name="2"></el-tab-pane>-->
    <!--        <el-tab-pane label="化验检查" name="3"></el-tab-pane>-->
    <!--        <el-tab-pane label="用药" name="4"></el-tab-pane>-->
    <!--      </el-tabs>-->
    <!--      <div style="width: 100%;height: 500px;overflow: auto" v-show="activeName === '1'">-->
    <!--        <clinical :info="obj"></clinical>-->
    <!--      </div>-->
    <!--      <div style="width: 100%;height: 500px;overflow: auto" v-show="activeName === '2'">-->
    <!--        <temperature></temperature>-->
    <!--      </div>-->
    <!--      <div style="width: 100%;height: 500px;overflow: auto" v-show="activeName === '3'">-->
    <!--        <test></test>-->
    <!--      </div>-->
    <!--      <div style="width: 100%;height: 500px;overflow: auto" v-show="activeName === '4'">-->
    <!--        <drug></drug>-->
    <!--      </div>-->
    <!--      <span slot="footer" class="dialog-footer">-->
    <!--    <el-button type="primary" @click="seeDialog = false" size="mini">保 存</el-button>-->
    <!--    <el-button @click="seeDialog = false" size="mini">取 消</el-button>-->
    <!--  </span>-->
    <!--    </el-dialog>-->
  </div>
</template>

<script>
import clinical from '../components/clinical'
import drug from '../components/drug'
import test from '../components/test'
import temperature from '../components/temperature'

export default {
  components: {
    clinical,
    drug,
    test,
    temperature
  },
  data() {
    return {
      tableData: [],
      page: {
        pageIndex: 1,
        pageSize: 10,
        realName: null,
        orderNum: null,
        orderTime: null,
        status: null,
        doctorId: null
      },
      total: 0,
      doctorList: [],
      seeDialog: false,
      activeName: '1',
      obj: {},
      userInfo: {}
    }
  },
  created() {
    this.findPage()
    this.userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
    if (this.userInfo.role === 3) {
      this.findAllDoctor()
    }
  },
  methods: {

    copyText(row, column, cell, event){
      // 双击复制
      let save = function (e){
        e.clipboardData.setData('text/plain',event.target.innerText);
        e.preventDefault();  //阻止默认行为
      }
      document.addEventListener('copy',save);//添加一个copy事件
      document.execCommand("copy");//执行copy方法
      this.$message({message: '复制成功', type:'success'})//提示
    },
    startOrder(id) {
      this.$confirm('确定接诊吗, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.post('/doctor-interrogationRecords/receivePatients?id=' + id).then(res => {
          if (res.data.code === 200) {
            this.findPage()
            this.$message.success(res.data.message)
          }
        })
      })
    },
    reset() {
      this.page.orderNum = null
      this.page.orderTime = null
      this.page.realName = null
      this.page.status = null
      this.page.doctorId = null
      this.page.pageIndex = 1
      this.page.pageSize = 10
      this.findPage()
    },
    findAllDoctor() {
      this.axios.post('/admin-doctor/findAll').then(res => {
        if (res.data.code === 200) {
          this.doctorList = res.data.data
        }
      })
    },
    handleSizeChange(val) {
      this.page.pageSize = val
      this.findPage()
    },
    handleCurrentChange(val) {
      this.page.pageIndex = val
      this.findPage()
    },
    getInOrderDetails(id) {
      this.$router.push('/orderDetails?id=' + id)
    },
    findPage() {
      this.axios.post('/admin-interrogationRecords/findPage', this.page).then(res => {
        if (res.data.code === 200) {
          this.tableData = res.data.data.data
          this.total = res.data.data.total
        }
      })
    }
  },
}
</script>

<style scoped lang="less">
.contain {
  width: 100%;
  height: 100%;

  .contain-header {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
  }

  .contain-body {
    width: 100%;
    height: calc(100% - 50px);
    background-color: #fff;
    padding: 1%;
    box-sizing: border-box;

    .body-header {
      width: 100%;
      height: 50px;
    }

    .body-table {
      width: 100%;
      height: calc(100% - 120px);
    }

    .body-page {
      width: 100%;
      height: 70px;
      display: flex;
      align-items: center;
    }
  }
}
</style>
